package com.feign.exception;

import feign.FeignException;
import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.Date;

/**
 * 异常处理
 * Created by yangjianbo on 2016/9/27.
 */
//@ControllerAdvice
public class HandlException {

    private Logger logger =  Logger.getLogger(HandlException.class);

    @ExceptionHandler(FeignException.class)
    @ResponseBody
    @ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
    public Object deal(FeignException ex) {
        logger.error(ex.getMessage(), ex);
        logger.info("*************OAuthProblemException ------ 异常信息已记录（" + new Date().toString()+ "） ------- ***********");
        return ex.getMessage();
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public String deal(RuntimeException ex) {
        logger.error(ex.getMessage(), ex);
        logger.info("*************RuntimeException ------ 未处理异常--请联系开发人员（" + new Date().toString()+ "） ------- ***********");
        return "出现未授检测异常，请联系开发人员，提高系统稳定性";
    }
}
